package com.zyasdk.service;

import android.content.Context;
import android.os.Handler;
import android.util.Base64;
import android.util.Log;

import com.zyasdk.enums.PayState;
import com.zyasdk.model.PayParm;
import com.zyasdk.model.PayRecord;
import com.zyasdk.util.AppInfoUtil;
import com.zyasdk.util.JSONHelper;
import com.zyasdk.util.LanguageUtil;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * play record
 */
public class PayRecordService extends BaseService {

    public PayRecordService(Context context) {
        super(context);
    }

    public void AddActivates(Handler handler, String pbindKey, PayState state,
                             int packId, String company, String payCountry, String payMoney,
                             String payUnit, String language, String orderNo) {
        PayRecord pr = new PayRecord();
        pr.setImei(AppInfoUtil.getIMEI(context));
        pr.setImsi(AppInfoUtil.getIMSI(context));
        pr.setLanguage(language);
        pr.setPackId(packId);
        pr.setPayCompany(company);
        pr.setPayCountry(payCountry);
        pr.setPayMoney(payMoney);
        pr.setPayState(state.getState());
        pr.setPayUnit(payUnit);
        pr.setPbindkey(pbindKey);
        pr.setOrderNo(orderNo);
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("MAR", new String(Base64.encode(
                JSONHelper.toJSON(pr).getBytes(), Base64.DEFAULT))));
        Log.i("result", "AddActivates1 ");
        ServiceTask.addTask(GetAPIUrl("AddPayRecord"), params);

    }

    public void AddActivates(Handler handler, PayParm pp) {
        PayRecord pr = new PayRecord();
        pr.setImei(AppInfoUtil.getIMEI(context));
        pr.setImsi(AppInfoUtil.getIMSI(context));
        pr.setPhone(AppInfoUtil.getPhoneNumber(context));
        pr.setLanguage(LanguageUtil.getLanguage(context));
        pr.setPackId(pp.getPackId());
        pr.setPayCompany(pp.getPayCompany());
        pr.setPayCountry(pp.getPayCountry());
        pr.setPayMoney(pp.getPayMoney());
        pr.setPayState(pp.getPayState());
        pr.setPayUnit(pp.getPayUnit());
        pr.setPbindkey(pp.getPbindkey());
        pr.setOrderNo(pp.getOrderNo());
        pr.setCodeRemark(pp.getCodeRemark());
        pr.setOperators(pp.getOperators());
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        Log.e("tag", "回传数据： " + JSONHelper.toJSON(pr));
        params.add(new BasicNameValuePair("MAR", new String(Base64.encode(
                JSONHelper.toJSON(pr).getBytes(), Base64.DEFAULT))));
        Log.i("result", "AddActivates2 ");
        ServiceTask.addTask(GetAPIUrl("AddPayRecord"), params);
    }
}
